<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>upload js sdk</title>
</head>
<body>
    
    <input type="file" id="input">
    <input type="button" id="upload" value="上传">

    <script src="./myun-upload-js-sdk.js"></script>
    <script>
        function setCookie(name,value,days) {
            var expires = "";
            if (days) {
                var date = new Date();
                date.setTime(date.getTime() + (days*24*60*60*1000));
                expires = "; expires=" + date.toUTCString();
            }
            document.cookie = name + "=" + (value || "")  + expires + "; path=/";
        }
        setCookie('Token', 'fdb1c9e9-4b84-48ae-96ea-35aea5d2c8f1', 30)
    </script>
    <script>
        var input = document.getElementById('input')
        var button = document.getElementById('upload')
        var token = 'fdb1c9e9-4b84-48ae-96ea-35aea5d2c8f1'

        button.addEventListener('click', function () {
            console.log('input', input)
            if (!input.files.length) {
                alert('请选择文件')
                return
            }
            var file = input.files[0]

            var upload = new MyunUpload({
                file: file,
                token: token,
                uploadUrl: `https://www.muducloud.com/storage/api/upload`,//单文件上传的接口（没有key的话必填）
                initUploadPartUrl: `https://www.muducloud.com/storage/api/init_upload_part`,//初始化分片上传的接口（没有key的话必填）
                uploadPartUrl: `https://www.muducloud.com/storage/api/upload_part`,//分片上传的接口（没有key的话必填）
                completeUploadPartUrl: `https://www.muducloud.com/storage/api/complete_upload_part`,//确认分片上传完成的接口（没有key的话必填）
                abortUploadPartUrl: `https://www.muducloud.com/storage/api/abort_upload_part`,

                success: function (data) {
                    console.log('data', data)
                    var url = data.url
                    console.log('上传成功', url)
                    alert('上传成功： ' + url)
                },
                errro: function (data) {
                    console.log('data', data)
                }
            })
            upload.startUpload()
        })
    </script>
</body>
</html>